﻿using CoreEx.Common.Validation;
using LinFu.IoC.Configuration;

namespace CoreEx.Common.Implementation.Validation
{
    /// <summary>
    /// Validates a single property within a target instance.
    /// </summary>
    /// <typeparam name="T"></typeparam>    
    [Implements(typeof(IPropertyValidator<>))]
    public class PropertyValidator<T> : Validator<T> ,IPropertyValidator<T>
    {        
        /// <summary>
        /// Validates a single property identified by <paramref name="propertyName"/> 
        /// </summary>
        /// <param name="target">The target instance to validate.</param>
        /// <param name="propertyName">The target property to validate.</param>
        /// <returns>A <see cref="string"/> that contains a textual representation of the broken rule, if any.</returns>
        public string Validate(T target, string propertyName)
        {
            return RulesValidator.Validate(ValidationRules.GetRules(propertyName), target);                        
        }             
    }
}
